package gui;

import java.util.Vector;

import model.ProcessType;
import model.Stack;
import model.TaskInfo;
import service.Service;
import dao.Dao;

public class NotStockPanel extends TabledFilteringPanel {

    public NotStockPanel() {
	super();

	String[] columnNamesArray = { "Name", "Number of trays",
		"Current process", "Next process", "Start time",
		"Current time", "Time remaining" };

	for (int i = 0; i < columnNamesArray.length; i++) {
	    columnNames.add(columnNamesArray[i]);
	}

	generateDataVector();

	setData(columnNames, data);
    }

    @Override
    protected void generateDataVector() {
	for (Stack x : Dao.getInstance().getStacks()) {
	    if (x.getCurrentProcess().getProcess().getProcessType() == ProcessType.NOT_IN_STOCK) {
		TaskInfo next = x.getNextProcess();

		Vector<Object> dataRow = new Vector<Object>();
		dataRow.add(x);
		dataRow.add(x.getNumberOfTrays());
		dataRow.add(x.getCurrentProcess().getProcess().getName());
		dataRow.add(next == null ? "" : next.getProcess().getName());
		dataRow.add(Service.getInstance().displayTime(
			x.getCurrentProcess().getStartTime().getTime()));
		dataRow.add(Service.getInstance().milisToTime(
			x.getCurrentProcess().calculateRunning()));
		dataRow.add(Service.getInstance().milisToTime(
			(long) x.getCurrentProcess().calculateTimeLeft()));

		data.add(dataRow);
	    }
	}
    }

}
